﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.Commands;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineMaterialsCommand.CommandHandlers
{
    public class DeleteMaterialsExamineCommandHandler : IRequestHandler<DeleteMaterialsExamineCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<MaterialsExamine> _examinematerRepository;
        public DeleteMaterialsExamineCommandHandler(IBaseRepository<MaterialsExamine> examinematerRepository)
        {
            _examinematerRepository = examinematerRepository;

        }
        public Task<APIRequst<int>> Handle(DeleteMaterialsExamineCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg = RequstCode.成功.ToString();
            var ment = _examinematerRepository.GetAll().FirstOrDefault(x => x.MaterialsId == request.materialsId);

            ment.isDel = true;
            ment.DeleteName = request.DeleteName;
            ment.DeleteTime = DateTime.Now;

            _examinematerRepository.Update(ment);
            return Task.FromResult(result);

        }

    }
}
